package a66weding.com.jiehuntong.common.uploadimage;

import android.app.Activity;
import android.app.ProgressDialog;
import android.os.AsyncTask;

import java.io.File;
import java.util.Map;

/**
 * Created by admin on 2016/9/22.
 */
public class HttpFileAsycTask extends AsyncTask<String, Integer, String> {
    //需要上传的文件
    private Map<String, File> files;
    private ProgressDialog pDialog;
    private Activity activity  ;
    private HttpFileUpTool.OnHttpResultListener onHttpResultListener;
    public HttpFileAsycTask(Map<String, File> files, Activity activity,HttpFileUpTool.OnHttpResultListener onHttpResultListener) {
        this.files = files;
        this.activity = activity;
        this.onHttpResultListener = onHttpResultListener;
    }

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        pDialog = new ProgressDialog(activity);
        pDialog.setCancelable(false) ;
        pDialog.setCanceledOnTouchOutside(false) ;
        pDialog.setMessage("数据上传中。。。");
        pDialog.show();
    }

    @Override
    protected String doInBackground(String... params) {
        return new HttpFileUpTool().post(params[0],files);
    }

    @Override
    protected void onPostExecute(String s) {
        pDialog.dismiss();
        if (onHttpResultListener!=null){
            this.onHttpResultListener.onResult(s);
        }
    }
}
